package com.teziyou.commodity.validator;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;

@SuppressWarnings({"rawtypes", "unchecked"})
public class BaseValidator {
	
	protected boolean validateInt(String value) {
		try {
			Integer.parseInt(value);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	protected boolean validateRequired(String value) {
		return StringUtils.isEmpty(value)?false:true;
	}
	
	/**
	 * 返回成功
	 * @param msg
	 * @return
	 */
	protected static String success(String msg) {
		Map result = new HashMap();
		result.put("isSuccess", true);
		result.put("msg", msg);
		return JSON.toJSONString(result);
	}
	
	/**
	 * 返回成功
	 * @param msg
	 * @return
	 */
	protected static String fail(String msg) {
		Map result = new HashMap();
		result.put("isSuccess", false);
		result.put("msg", msg);
		return JSON.toJSONString(result);
	}

}
